<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    var maximumImportance = function (n, roads) {
      let ins = Array(n).fill(0)
      for (let [a, b] of roads) {
        ins[a]++
        ins[b]++
      }
      ins.sort((a, b) => a - b)
      return ins.reduce((a, b, c) => a + b * (c + 1), 0)
    };
    console.log(maximumImportance(n = 5, roads = [[0, 1], [1, 2], [2, 3], [0, 2], [1, 3], [2, 4]]))
  </script>
</body>

</html>